package cn.lds.j375.healthexam.configuration;

import cn.lds.j375.healthexam.convert.DateConvert;

import cn.lds.j375.healthexam.interceptor.DoctorAuthorityInterceptior;
import cn.lds.j375.healthexam.interceptor.LoginInterception;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfigurer implements WebMvcConfigurer {

    @Autowired
    private DateConvert dateConvert;

    @Autowired
    private LoginInterception loginInterception;

    @Autowired
    private DoctorAuthorityInterceptior doctorAuthorityInterceptior;


    /**
     * 添加自定义类型转换器
     *
     * @param registry
     */
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(dateConvert);
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterception)
                .addPathPatterns("/**")
                .excludePathPatterns("/")
                .excludePathPatterns("/bootstrap/**"
                        , "/bootstrap-progressbar/**"
                        , "/css/**"
                        , "/fastclick/**"
                        , "/Flot/**"
                        , "/flot.curvedlines/**"
                        , "/flot.orderbars/**"
                        , "/font-awesome/**"
                        , "/gauge.js/**"
                        , "/iCheck/**"
                        , "/images/**"
                        , "/jquery/**"
                        , "/jqvmap/**"
                        , "/js/**"
                        , "/nprogress/**")

                .excludePathPatterns("/user/**");

        registry.addInterceptor(doctorAuthorityInterceptior)
                .addPathPatterns("/appointment_record/appoint_list");
    }


}
